<template>
  <div>
    <div class="CopyBox">
      <div v-bind="$attrs">
        <slot />
      </div>
      <el-tooltip effect="dark" content="点击复制" placement="top">
        <el-icon @click="copyBtn">
          <CopyDocument />
        </el-icon>
      </el-tooltip>
    </div>
    <div class='text-color-info'>{{hint}}</div>
  </div>
</template>
<script setup lang="ts">
import { onMounted, getCurrentInstance, onUnmounted } from 'vue';
const { proxy } = getCurrentInstance() as any;
const props = withDefaults(
  defineProps<{
    data?: any;
    hint?: string;
  }>(),
  {

  },
);
const copyBtn = () => {
  proxy.$copy(props.data)
  emit('copyBtn', props.data)
}
const emit = defineEmits<{
  //fn为父组件引入子组件是定义的子组件事件属性，可随意定义
  (event: 'copyBtn', val: any): void;
}>();
onMounted(() => { });
onUnmounted(() => { });
</script>
<style scoped lang="scss">
.CopyBox {
  display: flex;
  align-items: center;

  .el-icon {
    display: none;
  }

  >* {
    margin-right: 8px;
  }

  &:hover {
    .el-icon {
      display: flex;

      &:hover {
        color: $primary;
      }
    }
  }
}
</style>
